import { RootState, RootThunkAction } from '@/types/store'
import { useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'
function useInitState<T extends keyof RootState> (
  action: RootThunkAction,
  reducerName: T
) {
  const dispatch = useDispatch()
  const state = useSelector((state: RootState) => state)
  // 获取用户信息

  // created
  useEffect(() => {
    dispatch(action)
  }, [dispatch])
  return state[reducerName]
}
export { useInitState }
